/**
 * 
 */
package com.ternnetwork.core.accesscontroll.entity;


import java.io.Serializable;
import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;




@Entity
@Table(name="AVO_USER_ROLE")
public class UserRole implements Serializable{

 /**
	 * 
	 */
	private static final long serialVersionUID = 1821439357696364763L;
	
 @EmbeddedId
 @AttributeOverrides( {
 @AttributeOverride(name="userId", column=@Column(name="USER_ID", nullable=false) ), 
 @AttributeOverride(name="roleId", column=@Column(name="ROLE_ID", nullable=false) ) } )
 private UserRoleId id;
	
 @ManyToOne(fetch=FetchType.EAGER)
 @JoinColumn(name="USER_ID", nullable=false, insertable=false, updatable=false)
 private User user; //用户
 
 @ManyToOne(fetch=FetchType.EAGER)
 @JoinColumn(name="ROLE_ID", nullable=false, insertable=false, updatable=false)
 private Role role;//角色
 
 @Temporal(TemporalType.TIMESTAMP)
 @Column(name="EXPIRED_DATE")
 private Date expiredDate;//过期日期
 
 @Temporal(TemporalType.TIMESTAMP)@Column(nullable=false,name="CREATE_TIME")
 private Date createTime=new Date();

 
 public UserRoleId getId() {
	return id;
}
public void setId(UserRoleId id) {
	this.id = id;
}

public User getUser() {
	return user;
}
public void setUser(User user) {
	this.user = user;
}

public Role getRole() {
	return role;
}
public void setRole(Role role) {
	this.role = role;
}



public Date getCreateTime() {
	return createTime;
}
public void setCreateTime(Date createTime) {
	this.createTime = createTime;
}



public Date getExpiredDate() {
	return expiredDate;
}
public void setExpiredDate(Date expiredDate) {
	this.expiredDate = expiredDate;
}
@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((id == null) ? 0 : id.hashCode());
	return result;
}
@Override
public boolean equals(Object obj) {
	if (this == obj) {
		return true;
		
	}
	if (obj == null) {
		return false;
	}
	if (getClass() != obj.getClass()) {
		return false;
	}
	UserRole other = (UserRole) obj;
	if (id == null) {
		if (other.id != null) {
			return false;
		}
	} else if (!id.equals(other.id)) {
		return false;
	}
	return true;
}
 
 
}
